<template>
  <div>
    <div class="header_img">
      <img src="http://1.117.75.96:8080/goods/header.png" alt="" />
    </div>

    <div class="header_nav">
      <div class="nav_box">
        <ul class="left_list">
          <li><a>华硕官网</a></li>
          <li><router-link to="/">商城首页</router-link></li>
          <li><a>企业采购</a></li>
          <li><a>驱动下载</a></li>
          <li><a>装机必备</a></li>
          <li><a>已旧换新</a></li>
        </ul>
        <ul class="right_list">
          <li v-if="!isLogin"><router-link to="/login">登录</router-link></li>
          <li v-if="!isLogin"><router-link to="/reg">注册</router-link></li>
          <li v-if="isLogin">
            <a>{{ user.username }}</a>
          </li>
          <li v-if="isLogin"><a @click.prevent="exit">退出</a></li>
          <li><a>消息</a></li>
          <li><a>我的订单</a></li>
          <li><a style="border-right: none">手机版</a></li>
          <li class="cart">
            <div class="title">
              <router-link to="/cart">购物车({{ store.state.cart.cart.length || 0 }})</router-link>
            </div>
            <div class="cart_list">
              <p v-show="!isLogin" class="xx">您还没有登录！登录后进入购物车</p>
              <div v-show="isLogin">
                <p v-if="store.state.cart.cart.length == 0" class="no-number">
                  购物车中还没有商品，赶紧选购吧！
                </p>
                <ul v-else>
                  <li
                    v-for="item in store.state.cart.cart"
                    @click="router.push({ name: 'Cart' })"
                  >
                    <img :src="item.url" alt="" />
                    <p class="t1">{{ item.name }}</p>
                    <p class="t2">X{{ item.number }}</p>
                  </li>
                </ul>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>

    <div class="header_nav2">
      <div class="content">
        <div class="logo">
          <router-link to="/">
            <img src="http://1.117.75.96:8080/goods/logo.png" alt="" />
            <img src="http://1.117.75.96:8080/goods/logo2.png" alt="" />
          </router-link>
        </div>

        <ul class="inlink">
          <li>
            <img src="http://1.117.75.96:8080/goods/UI/mini1.png" alt="" /><span
              >华硕电脑官网</span
            >
          </li>
          <li>
            <img src="http://1.117.75.96:8080/goods/UI/mini2.png" alt="" /><span
              >ROG专区</span
            >
          </li>
          <li>
            <img src="http://1.117.75.96:8080/goods/UI/mini3.png" alt="" /><span
              >多彩a豆</span
            >
          </li>
          <li>
            <img src="http://1.117.75.96:8080/goods/UI/mini4.png" alt="" /><span
              >华硕好屏</span
            >
          </li>
        </ul>

        <div class="search">
          <input
            type="text"
            name="search"
            id=""
            v-model="search"
            placeholder="新人礼"
          />
          <span></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref } from "vue-demi";
import store from "../store";


let search = ref("");
let user=computed(()=>{
  return store.state.user.userinfo
})
let isLogin=computed(()=>{
  return Object.keys(store.state.user.userinfo).length!=0
})

//退出登录
let exit=()=>{
  store.dispatch("user/handleLogOut")
}
</script>

<style lang="less" scoped>
.header_img {
  max-width: 1920px;
  margin: auto;

  img {
    display: block;
    width: 100%;
    height: 100%;
    top: 0;
  }
}
.header_nav {
  width: 100%;
  height: 40px;
  background: #404040;

  .nav_box {
    width: 1226px;
    margin: 0 auto;

    .left_list {
      float: left;

      li {
        display: inline-block;
      }

      li:last-child a {
        border-right: none;
      }
    }

    .right_list {
      float: right;

      li {
        display: inline-block;

        :last-child a {
          border-right: none;
        }
      }

      .cart {
        position: relative;
        padding: 0 15px 0 48px;
        color: #ccc;
        line-height: 40px;
        font-size: 15px;
        background-color: #555;
        background-image: url(http://1.117.75.96:8080/goods/cart.png);
        background-size: 29px 27px;
        background-position: 15px 6px;
        background-repeat: no-repeat;
        cursor: pointer;

        .title {
          font-size: 15px;
          line-height: 40px;
          color: #ccc;
          margin: 0 12px;
        }

        .cart_list {
          position: absolute;
          right: 0;
          top: 40px;
          width: 327px;
          min-height: 95px;
          background: #fff;
          box-shadow: 0px 4px 6px 4px rgba(210, 210, 210, 50%) !important;
          z-index: 9;
          display: none;

          .no-number,
          .xx {
            color: #222;
            line-height: 95px;
            text-align: center;
          }

          ul {
            width: 327px;
            min-height: 95px;
            background: #fff;

            li {
              margin: 20px 0;
              width: 100%;
              max-height: 380px;
              padding-left: 20px;
              overflow-x: hidden;
              overflow-y: auto;
              box-sizing: border-box;
              display: flex;
              align-items: center;
              color: #222;

              img {
                width: 60px;
                height: 60px;
                margin-right: 10px;
                background: #f7f7f7;
                line-height: 20px;
              }

              .t1 {
                float: left;
                line-height: 20px;
                padding-top: 12px;
                width: 126px;
                margin-right: 10px;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                word-break: break-all;
              }

              .t2 {
                padding-top: 12px;
                width: 74px;
                text-align: right;
              }
            }
          }
        }
      }

      .cart:hover {
        background-color: #fff;

        .title a {
          color: #fa3c72 !important;
        }

        .cart_list {
          display: block;
        }
      }
    }

    a {
      font-size: 15px;
      line-height: 40px;
      color: #ccc;
      padding: 0 12px;
      border-right: 1px solid #747474;
    }

    a:hover {
      color: #fff;
    }
  }
}

.header_nav2 {
  position: relative;
  width: 100%;
  height: 100px;
  background: #fff;

  .content {
    height: 100%;
    line-height: 100px;
    font-size: 0;
    white-space: nowrap;
    width: 1226px;
    margin: 0 auto;

    .logo {
      display: inline-block;
      width: 235px;
      margin-right: 40px;

      img {
        height: 60px;
        vertical-align: middle;
      }
    }

    .inlink {
      width: 690px;
      white-space: nowrap;
      overflow: hidden;
      display: inline-block;
      vertical-align: middle;

      li {
        display: inline-block;
        margin-right: 30px;
        height: 100px;
        cursor: pointer;

        img {
          width: 20px;
          height: 20px;
          margin-right: 3px;
        }

        span {
          font-size: 15px;
          color: #222;
        }
      }
    }

    .search {
      width: 242px;
      height: 30px;
      vertical-align: top;
      margin-top: 34px;
      display: inline-block;
      position: relative;

      input {
        width: 194px;
        height: 100%;
        padding: 0 10px 0 15px;
        font-size: 14px;
        line-height: 14px;
        color: #555;
        border: none;
        outline: none;
        background-color: #e9e9e9;
        border-radius: 15px 0 0 15px;
        box-sizing: border-box;
        float: left;
      }

      span {
        float: right;
        width: 48px;
        height: 100%;
        border-radius: 0 15px 15px 0;
        background-image: url(http://1.117.75.96:8080/goods/UI/search.png);
        background-size: 15px 18px;
        background-repeat: no-repeat;
        background-position: 15px 6px;
        background-color: #ccc;
        cursor: pointer;
      }
    }
  }
}
</style>
